﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Luna
{
	public delegate bool Predicate2<T>(T value1, T value2);

	public static class ArrayExtension
	{
		public static int indexOf<T>(this IList<T> array, T value) {
			for (int i = 0; i < array.Count; i++)
				if (value.Equals(array[i]))
					return i;
			return -1;
		}

		public static int findIndex<T>(this IList<T> array, Predicate<T> pred) {
			for (int i = 0; i < array.Count; i++)
				if (pred(array[i])) return i;
			return -1;
		}

		public static int test<T>(this IList<T> arr, string value) {
			return -1;
		}

		public static string join<T>(this IList<T> arr, string seperator) {
			return join(arr, seperator, null);
		}

		public static string join<T>(this IList<T> arr, string separator, Func<T, string> convert) {
			StringBuilder b = new StringBuilder(20);
			for (int i = 0; i < arr.Count; i++) {
				if (i > 0) b.Append(separator);
				b.Append(convert != null ? convert(arr[i]) : arr[i].ToString());
			}
			return b.ToString();
		}

		public static string join(this IList arr, string separator, Func<object, string> convert) {
			StringBuilder b = new StringBuilder(20);
			for (int i = 0; i < arr.Count; i++) {
				if (i > 0) b.Append(separator);
				b.Append(convert != null ? convert(arr[i]) : arr[i].ToString());
			}
			return b.ToString();
		}
	}
}
